{include file="public/layout.htm" /}
<style type="text/css">
    .show {display: block;}
    .none {}
</style>
<body class="back-c">
    <div class="ey-content">
        <div class="form-title">填写物流信息</div>
        <form id="postForm">
            <input type="hidden" name="_ajax" value="1">
            <input type="hidden" name="weappAjax" value="1">
            <input type="hidden" name="express_id" id="express_id">
            <input type="hidden" name="express_name" id="express_name">
            <input type="hidden" name="express_code" id="express_code">
            <input type="hidden" name="prom_type" id="prom_type" value="0">
            <input type="hidden" name="order_id" value="{$OrderData.order_id}">
            <input type="hidden" name="users_id" value="{$OrderData.users_id}">
            <input type="hidden" name="consignee" value="{$OrderData.consignee}">
            <input type="hidden" name="order_code" value="{$OrderData.order_code}">
            <input type="hidden" name="address" value="{$OrderData.province}{$OrderData.city}{$OrderData.district}{$OrderData.address}">
            <div class="item-wrap mt0">
                <div class="form-wrap more-wrap">
                    <div class="label">
                        <span>收货地址</span>
                    </div>
                    <div class="value" style="white-space: unset;">
                        {$OrderData.province} {$OrderData.city} {$OrderData.district} {$OrderData.address} 
                    </div>
                </div>

                <div class="form-wrap delivery-way">
                    <div class="label">
                        <span>发货方式</span>
                    </div>
                    <span class="w80-button on" onclick="promType(this, 0);">物流发货</span>
                    <span class="w80-button" onclick="promType(this, 1);">无需物流</span>
                </div>

                <div  {eq name='$OrderData.prom_type' value='1'} style="display: none;" {/eq} id="ShippingInfo">
                    <div class="form-wrap more-wrap">
                        <div class="label">
                            <span>物流公司</span>
                        </div>
                        <div class="ey-input">
                            <div class="selected">
                                <select class="" id="select_express" onchange="selectExpress(this);">
                                    <option value="0">请选择物流公司</option>
                                    {volist name="$express" id="vo"}
                                    <option value="{$vo.express_id}" code="{$vo.express_code}" name="{$vo.express_name}" {eq name="$vo.express_code" value="$OrderData.express_code"}selected{/eq}>{$vo.express_name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="form-wrap">
                        <div class="label">
                            <span>快递单号</span>
                        </div>
                        <div class="ey-input">
                            <div class="ey-input-wrapper">
                                <input type="text" value="{$OrderData.express_order}" name="express_order" id="express_order" class="ey-input-input" placeholder="请输入快递单号">
                            </div>
                        </div>
                    </div>
                </div>

                <div class="form-wrap" {if condition='$OrderData.prom_type == 0 && $OrderData.prom_type_virtual == false'} style="display: none;" {/if} id="VirtualDelivery">
                    <div class="label">
                        <span>给买家回复</span>
                    </div>
                    <div class="ey-input">
                        <div class="ey-input-wrapper">
                            <input type="text" value="{$OrderData.virtual_delivery}" name="virtual_delivery" id="virtual_delivery" class="ey-input-input" placeholder="请输入回复">
                        </div>
                    </div>
                </div>
            </div>
        </form>
        <div class="w100-footer-wrap">
            <button onclick="checkForm();">
            {if condition='$OrderData.order_status == 1'}确认发货{elseif condition='$OrderData.order_status == 2'}修改保存{/if}
            </button>
        </div>
    </div>

    <script type="text/javascript">
        function promType(obj, value) {
            $('#prom_type').val(value);
            if (1 === parseInt(value)) {
                $('#ShippingInfo').hide();
                $('#VirtualDelivery').show();
            } else {
                $('#ShippingInfo').show();
                $('#VirtualDelivery').hide();
            }
            $(obj).addClass('on').siblings().removeClass('on');
        }

        // 下拉框选择
        function selectExpress(obj) {
            // 选中的对象
            var selectObj = $(obj).find("option:selected");
            // 赋值隐藏域
            $('#express_id').val($(selectObj).attr('value'));
            $('#express_name').val($(selectObj).attr('name'));
            $('#express_code').val($(selectObj).attr('code'));
        }

        function checkForm() {
            //询问框
            layer.open({
                btn: ['确定', '取消'],
                content: '此操作不可恢复，确认发货？',
                yes: function(index) {
                    layer.closeAll();
                    layerLoading();
                    $.ajax({
                        url : "{:url('Shop/order_send_operating')}",
                        data: $('#postForm').serialize(),
                        type: 'post',
                        dataType: 'json',
                        success: function(res) {
                            if (1 == res.code) {
                                layer.closeAll();
                                if (!res.data.email && !res.data.mobile && !res.data.notice) {
                                    layerMsg(res.msg, 1.5, function() {
                                        window.location.href = "{:weapp_url('Mbackend/Shop/index')}";
                                    });
                                } else {
                                    if (res.data.email) unifySendEmail(res.data.email);
                                    if (res.data.mobile) unifySendMobile(res.data.mobile);
                                    if (res.data.weChat) unifySendWeChat(res.data.weChat);
                                    layerMsg('发货成功', 1.5, function() {
                                        window.location.href = "{:weapp_url('Mbackend/Shop/index')}";
                                    });
                                }
                            } else {
                                layer.closeAll();
                                layerAlert(res.msg);
                            }
                        }
                    });
                }
            });
        }
    </script>
</body>
{include file="public/footer.htm" /}